package controller

import (
	"context"
	v1 "tFilm4/api/v1"
	"tFilm4/internal/model"
	"tFilm4/internal/service"
)

type cMovieSession struct{}

var MovieSession = cMovieSession{}

func (c *cMovieSession) CreateMovieSession(ctx context.Context, req *v1.CreateSessionReq) (res *v1.CreateSessionRes, err error) {
	err = service.MovieSession().CreateMovieSession(ctx, model.CreateMovieSessionInput{
		MovieId:      req.MovieId,
		HallId:       req.HallId,
		StartTime:    req.StartTime,
		EndTime:      req.EndTime,
		SessionPrice: req.SessionPrice,
		SeatTable:    req.SeatTable,
	})
	return
}

func (c *cMovieSession) GetSessionList(ctx context.Context, req *v1.GetSessionListReq) (res *v1.GetSessionListRes, err error) {
	count, list, err := service.MovieSession().GetSessionList(ctx, model.GetSessionInput{
		PageSize:  req.PageSize,
		PageNum:   req.PageNum,
		SearchKey: req.SearchKey,
	})
	res = &v1.GetSessionListRes{
		MovieSessionInfo:  list,
		MovieSessionCount: count,
	}
	return
}

func (c *cMovieSession) GetSessionListByHallTime(ctx context.Context, req *v1.GetSessionListByHallTimeReq) (res *v1.GetSessionListByHallTimeRes, err error) {
	count, infos, err := service.MovieSession().GetSessionListByHallTime(ctx, model.GetSessionListByHallTimeInput{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		HallId:    req.HallId,
	})
	res = &v1.GetSessionListByHallTimeRes{
		MovieSessionInfo:  infos,
		MovieSessionCount: count,
	}
	return
}

func (c *cMovieSession) GetSessionListByMovieTime(ctx context.Context, req *v1.GetSessionListByMovieTimeReq) (res *v1.GetSessionListByMovieTimeRes, err error) {
	count, infos, err := service.MovieSession().GetSessionListByMovieTime(ctx, model.GetSessionListByMovieTimeInput{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		MovieId:   req.MovieId,
	})
	if err != nil {
		return nil, err
	}
	res = &v1.GetSessionListByMovieTimeRes{
		MovieSessionInfo:  infos,
		MovieSessionCount: count,
	}
	return
}

func (c *cMovieSession) GetSessionById(ctx context.Context,req *v1.GetSessionByIdReq) (res *v1.GetSessionByIdRes,err error){
	info, err := service.MovieSession().GetSessionById(ctx, req.SessionId)
	res = &v1.GetSessionByIdRes{MovieSessionInfo: info}
	return
}